package com.abei.gas.service.Impl;

import com.abei.gas.entity.Device;
import com.abei.gas.entity.Repairorder;
import com.abei.gas.mapper.DeviceMapper;
import com.abei.gas.mapper.RepairorderMapper;
import com.abei.gas.service.RepairorderService;
import com.abei.gas.vo.DataVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RepairorderServiceImpl extends ServiceImpl<RepairorderMapper, Repairorder> implements RepairorderService {
    @Resource
    private RepairorderMapper repairorderMapper;
    @Override
    public DataVo<Repairorder> findAll(Integer page, Integer limit) {
        List<Repairorder> c=repairorderMapper.selectList(null);
        DataVo<Repairorder> datavo=new DataVo<>();
        datavo.setCode(0);
        datavo.setMsg("");
        IPage<Repairorder> cardpage=new Page<>(page,limit);
        IPage<Repairorder> result=repairorderMapper.selectPage(cardpage,null);
        datavo.setCount(result.getTotal());
        c=result.getRecords();
        datavo.setData(c);
        return datavo;
    }

    @Override
    public DataVo<Repairorder> findById(String number) {
        QueryWrapper<Repairorder> u = new QueryWrapper<>();
        u.like("id",number);
        List<Repairorder> cardList=repairorderMapper.selectList(u);
        DataVo<Repairorder> dataVO=new DataVo<>();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Integer num = repairorderMapper.selectCount(null);
        dataVO.setCount(Long.valueOf(num));
        dataVO.setData(cardList);
        return dataVO;
    }
    @Override
    public void deleteById(String deviceid) {
        Map<String,Object> columMap=new HashMap<>();
        columMap.put("id",deviceid);
        int i=repairorderMapper.deleteByMap(columMap);
        System.out.println(i);
    }
}
